app=$1

if [ "$app" == "" ]; then 
  echo "./run-17.sh 目录名"
  exit 1;
fi

if [ ! -d $app ]; then
  echo "不存在目录 $app"
  exit 1;
fi

app=`echo ${app//\//}`

echo "正在启动 $app ..."
 
host_ip=$(docker network inspect bridge | grep Gateway | awk '{print $NF}' | sed 's/"//g')

docker kill $app ; docker rm $app

vp=""

if [ "$app" == "mp-admin-api" -o "$app" == "mp-gateway-api" ]; then
   vp=" --privileged=true -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v /etc/docker:/etc/docker  -v /:/r "
fi

if [ "$app" == "mp-admin-api" ]; then
   vp="$vp -m 2048m "
else
   vp="$vp -m 1024m "
fi

if [ "$app" == "mp-gateway-api" ]; then
   vp=" $vp -p 9898:80 " 
fi

touch g-version.txt
v=$(cat g-version.txt)
if [ "$v" == "" ]; then
	v=10001
fi

v2=$(($v+1))

echo $v2 > g-version.txt


docker run -d --name $app --net vm \
  $vp  \
  -v "$(pwd)/$app":/app-x \
  -v  /app:/app \
  -v  /app/java/start.sh:/app-x/exec.sh \
  -w /app-x  \
  --add-host=mysql:172.20.0.1 \
  --add-host=mongo:172.20.0.1 \
  --add-host=thc:172.20.0.1 \
  --add-host=thc-dev:172.20.0.1 \
  --add-host=redis:172.20.0.1 \
  --add-host=rabbitmq:172.20.0.1 \
  --add-host=es:172.20.0.1 \
  --add-host=minio:172.20.0.1 \
  openjdk:17  /bin/bash  /app-x/exec.sh $app
